<!--
 - MineAdmin is committed to providing solutions for quickly building web applications
 - Please view the LICENSE file that was distributed with this source code,
 - For the full copyright and license information.
 - Thank you very much for using MineAdmin.
 -
 - @Author X.Mo<root@imoi.cn>
 - @Link   https://gitee.com/xmo/mineadmin-vue
-->

<template>
  <a-drawer v-model:visible="visible" width="80%" :footer="false">
    <template #title>托盘数据#{{currentRow.number}}#包裹总数{{currentRow.parcel_count}}</template>
    <!-- CRUD 组件 -->
    <ma-crud :options="crud" :columns="columns" ref="crudRef">

    </ma-crud>
  </a-drawer>
</template>

<script setup>
import { ref, reactive,inject } from 'vue'
import  trayList  from '@/api/warehouse/trayList'
import { Message } from '@arco-design/web-vue'

const crudRef = ref()
const ParentcrudRef = inject('crudRef')
const visible = ref(false)
const currentRow = ref({ id: undefined ,number:undefined})

const open = (row) => {
  currentRow.value = row
  crudRef.value.requestData()
  visible.value = true
}

const crud = reactive({
  autoRequest: false,
  api: trayList.getList,
  showIndex: false,
  pageLayout: 'fixed',
  rowSelection: { showCheckedAll: true },
  operationColumn: true,
  operationColumnWidth: 160,
  showTools: false,
  summary:[
    {dataIndex:'count',action:'sum'}
  ],
  showSummary: true,
  beforeAdd: (form) => {
    form.tray_id = currentRow.value?.id
    return true
  },
  add: { show: true, api: trayList.save, auth: ['system:trayList:save'] },
  edit: { show: true, api: trayList.update, auth: ['system:trayList:update'] },
  delete: {
    show: true,
    api: trayList.deletes, auth: ['system:trayList:delete'],
  },
  recovery: { show: true, api: trayList.recoverys, auth: ['system:trayList:recovery'] },
  beforeRequest: (params) => params.tray_id = currentRow.value?.id
})

const columns = reactive([
  { title: 'ID', dataIndex: 'id', addDisplay: false, editDisplay: false, width: 50, hide: true },
  {
    title: '托盘编号', dataIndex: 'number', search: true, width: 220,
    addDisplay: false, editDisplay: false,
    commonRules: [{ required: true, message: '托盘编号必填' }],
  },
  {
    title: '包裹数量', dataIndex: 'count', width: 220,
    commonRules: [{ required: true, message: '包裹数量必填' }],
  },
])

defineExpose({ open })
</script>

<style scoped>
</style>